import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.DriverManager;

import javax.swing.BorderFactory;
import javax.swing.ButtonModel;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;


public class RegisterPanel extends JPanel  {

        JPanel panel = new JPanel();
        JPanel panelt = new JPanel();
        JPanel panelc = new JPanel();
        JPanel panelc1 = new JPanel();
        JPanel panelc2 = new JPanel();
        JPanel panelb = new JPanel();
        JButton submit=new JButton();
        JButton home=new JButton();
        JButton add=new JButton();
        JButton delete=new JButton();
        String[] cols={"Add","Term", "Course Title","Course Number", "Professor", "Meeting Info", "Credits"};
        String[] cols2={"Delete","Term", "Course Title","Course Number", "Professor", "Meeting Info", "Credits"};
        Boolean j=false;
        Object data[][]={};
        JTable table;
        JTable table2;
        DefaultTableModel dtm,dtm2;
        int row=0,row2=0;
        Image img;
        
        public RegisterPanel() {
        	img=new ImageIcon("register_background.png").getImage();
    		setOpaque(false);
                setLayout(new BorderLayout());
                add(panel,BorderLayout.PAGE_START);
                
                panel.setBackground(Color.WHITE);
                add(panel, BorderLayout.NORTH);
                panel.setPreferredSize(new Dimension(600,400));
                panel.setOpaque(false);
                
                //-----TOP PANEL-----
                panelt.setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY, 1, false));
                panelt.setBackground(Color.WHITE);
        panelt.setLayout(new BorderLayout());
        panelt.setPreferredSize(new Dimension(600,40));
        JLabel ds=new JLabel(MenuPanel.fname+ " "+MenuPanel.lname);
        JLabel name=new JLabel("1234567");
        panelt.add(ds,BorderLayout.NORTH);
        panelt.add(name,BorderLayout.SOUTH);
        panel.add(panelt, BorderLayout.NORTH);
       panelt.setOpaque(false);
        //-----CENTER PANEL-----
        panelc.setBackground(Color.WHITE);
        panelc.setLayout(new BorderLayout());
        panelc.setOpaque(false);
        
        //-----CENTER PANEL 1-----
        panelc1.setBackground(Color.WHITE);
        panelc1.setLayout(new BorderLayout());
        panelc1.setBorder(BorderFactory.createTitledBorder("Availible Courses:"));
        
        panelc2.setBackground(Color.WHITE);
        panelc2.setLayout(new BorderLayout());
        panelc2.setBorder(BorderFactory.createTitledBorder("Register Courses:"));

        initialize();
        
//        model.addRow(data[0]);
//        model.addRow(data[1]);
//        model.addRow(data[2]);
//        model.addRow(data[3]);
//        model.addRow(data[4]);
//        model.addRow(data[5]);
//        model.addRow(data[6]);
//        
//        model.isCellEditable(0,0);
        //table = new JTable(model);        

        TableColumn column0;
        column0 = table.getColumnModel().getColumn(0);
        column0.setPreferredWidth(25);
                
                TableColumn column1;
        column1 = table.getColumnModel().getColumn(1);
        column1.setPreferredWidth(45);
        
        TableColumn column2;
        column2 = table.getColumnModel().getColumn(2);
        column2.setPreferredWidth(135);
        
        TableColumn column3;
        column3 = table.getColumnModel().getColumn(3);
        column3.setPreferredWidth(45);
                
        TableColumn column4;
        column4 = table.getColumnModel().getColumn(4);
        column4.setPreferredWidth(50);
        
        TableColumn column5;
        column5 = table.getColumnModel().getColumn(5);
        column5.setPreferredWidth(184);
        
        TableColumn column6;
        column6 = table.getColumnModel().getColumn(6);
        column6.setPreferredWidth(34);
        
        table.setFillsViewportHeight(true);
                JScrollPane j = new JScrollPane(table);
                j.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
                
                panelc1.setPreferredSize(new Dimension(550,170));
                panelc1.add(add, BorderLayout.SOUTH);
                panelc1.add(j, BorderLayout.CENTER);
                panelc.add(panelc1, BorderLayout.NORTH);
                
                
                //-----CENTER PANEL 2-----
                //model2.isCellEditable(0,0);
               // table2 = new JTable(model2);        

        TableColumn column00;
        column00 = table2.getColumnModel().getColumn(0);
        column00.setPreferredWidth(35);
                
                TableColumn column11;
        column11 = table2.getColumnModel().getColumn(1);
        column11.setPreferredWidth(45);
        
        TableColumn column22;
        column22 = table2.getColumnModel().getColumn(2);
        column22.setPreferredWidth(135);
        
        TableColumn column33;
        column33 = table2.getColumnModel().getColumn(3);
        column33.setPreferredWidth(45);
                
        TableColumn column44;
        column44 = table2.getColumnModel().getColumn(4);
        column44.setPreferredWidth(50);
        
        TableColumn column55;
        column55 = table2.getColumnModel().getColumn(5);
        column55.setPreferredWidth(184);
        
        TableColumn column66;
        column66 = table2.getColumnModel().getColumn(6);
        column66.setPreferredWidth(34);
        
        JScrollPane j2 = new JScrollPane(table2);
                j2.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
                
                table2.setFillsViewportHeight(true);
                panelc2.setPreferredSize(new Dimension(550,135));
                panelc2.add(j2, BorderLayout.CENTER);
                panelc2.add(delete, BorderLayout.SOUTH);
                panelc.add(panelc2, BorderLayout.SOUTH);
                
                
                panelc.setPreferredSize(new Dimension(600,310));
                panelc.setBackground(Color.WHITE);
                panel.add(panelc, BorderLayout.CENTER);
                
                
                //-----BASE PANEL-----
                panelb.setBackground(Color.WHITE);
                //panelb.setPreferredSize(new Dimension(600,20));
                panelb.setLayout(new BorderLayout());
                //panelb.add(submit, BorderLayout.WEST);
                panelb.add(home, BorderLayout.CENTER);
                panel.add(panelb, BorderLayout.SOUTH);
                add(panel, BorderLayout.PAGE_START);
                panelb.setOpaque(false);
                
                final ImageIcon ho=new ImageIcon("home_button.png");
        		final ImageIcon cho=new ImageIcon("home_cbutton.png");
        		final ImageIcon ad=new ImageIcon("add_button.png");
        		final ImageIcon cad=new ImageIcon("add_cbutton.png");
        		final ImageIcon de=new ImageIcon("delete_button.png");
        		final ImageIcon cde=new ImageIcon("delete_cbutton.png");
        		button(home,ho);
        		button(add,ad);
        		button(delete,de);
                
                home.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e){
                
                remove(panel);
                add(new MenuPanel(), BorderLayout.PAGE_START);
                validate();
                repaint();
                
            }
    });
                home.setContentAreaFilled(false);
                home.setIcon(ho);
                home.setRolloverIcon(cho);
                home.setPressedIcon(cho);
                home.getModel().addChangeListener(new ChangeListener() {
        		        @Override
        		        public void stateChanged(ChangeEvent e) {
        		            ButtonModel model = (ButtonModel) e.getSource();
        		            if (model.isRollover()) {
        		            	home.setIcon(cho);
        		            } else {
        		            	home.setIcon(ho);
        		            }// etc ...//  if (model.isPressed()) {
        		         }
        		    });
                
                add.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e){
                
                int c = row;
                for(int i =0; i<c; i++){
                        String s=(String) table.getModel().getValueAt(i, 3);
                        Boolean b = (Boolean) table.getModel().getValueAt(i, 0);
                        
                        if(b==true)
                                {
                        			System.out.println(s);
                                    // dtm.removeRow(i);
                                     //dtm2.addRow(data[i]);
                                     add(s);
                                     b=false;
                                        
                                        
                                }
                        
                }
                
            }
    });
                add.setContentAreaFilled(false);
                add.setIcon(ad);
                add.setRolloverIcon(cad);
                add.setPressedIcon(cad);
                add.getModel().addChangeListener(new ChangeListener() {
        		        @Override
        		        public void stateChanged(ChangeEvent e) {
        		            ButtonModel model = (ButtonModel) e.getSource();
        		            if (model.isRollover()) {
        		            	add.setIcon(cad);
        		            } else {
        		            	add.setIcon(ad);
        		            }// etc ...//  if (model.isPressed()) {
        		         }
        		    });
                
                delete.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e){
                
                int c = row2;
                for(int i =0; i<dtm2.getRowCount(); i++){
                        String s=(String) table2.getModel().getValueAt(i, 3);
                        Boolean b = (Boolean) table2.getModel().getValueAt(i, 0);
                        //System.out.println(b);
                        if(b==true)
                                {
                        				System.out.println(s);
                                        dtm2.removeRow(i);
                                        //dtm.addRow(data[i]);
                                        i--;
                                        delete(s);
                                        
                                }
                        
                }
                
            }
    });
                delete.setContentAreaFilled(false);
                delete.setIcon(de);
                delete.setRolloverIcon(cde);
                delete.setPressedIcon(cde);
                delete.getModel().addChangeListener(new ChangeListener() {
        		        @Override
        		        public void stateChanged(ChangeEvent e) {
        		            ButtonModel model = (ButtonModel) e.getSource();
        		            if (model.isRollover()) {
        		            	delete.setIcon(cde);
        		            } else {
        		            	delete.setIcon(de);
        		            }// etc ...//  if (model.isPressed()) {
        		         }
        		    });
        
        }
        
        

        private void initialize(){
        	//available courses
        	dtm=new DefaultTableModel(data,cols){
        		public Class getColumnClass(int c) {
                    switch (c) {
                      case 0: return Boolean.class;
                      default: return String.class;
                    }   
                }
        		 @Override
               public boolean isCellEditable(int row, int col) {
                    switch (col) {
                        case 0:
                            return true;
                        default:
                            return false;
                     }
               }
               
        	};
        	table=new JTable(dtm);
        	//int row=0;
        	
        	try{
        		String dName = "com.mysql.jdbc.Driver";
        		String url = "jdbc:mysql://db4free.net:3306/studentreg14?user=studentreg14&password=KCTSkcts";
        		Connection con = DriverManager.getConnection(url);
        		java.sql.Statement mysqlStatement = con.createStatement();
        		java.sql.ResultSet resultSet = mysqlStatement.executeQuery("SELECT cu.term, cu.start_time, cu.end_time, cu.days, cu.instructor, ca.course_name, ca.course_number, ca.credit_hours, cu.CID FROM next_semester_course_list AS cu JOIN course_catalog AS ca ON cu.CID = ca.CID GROUP BY course_name");
        		
        		while (resultSet.next()) {
        			row+=1;
        			String term=resultSet.getString(1);
        			String start_time="";//=resultSet.getString(2);
        			String end_time="";//=resultSet.getString(3);
        			//String days;//=resultSet.getString(4);
        			String instructor=resultSet.getString(5);
        			String course_name=resultSet.getString(6);
        			String course_number=resultSet.getString(7);
        			
        			int credit_hours=resultSet.getInt(8);
        			String cid=resultSet.getString(9);
        			String days="";
        			
        			try{
        				String dName2 = "com.mysql.jdbc.Driver";
        				String url2 = "jdbc:mysql://db4free.net:3306/studentreg14?user=studentreg14&password=KCTSkcts";
        				Connection con2 = DriverManager.getConnection(url2);
        				java.sql.Statement mysqlStatement2 = con2.createStatement();
        				//java.sql.ResultSet resultSet = mysqlStatement.executeQuery("SELECT course_name, start_time, days From course_catalog, current_course_total_list WHERE course_catalog.CID IN (SELECT CID FROM current_course_total_list WHERE SID='"+MenuPanel.SID+"')");//course_catalog.CID IN (SELECT CID FROM current_course_total_list WHERE SID='"+MenuPanel.SID+"')");// AND current_course_total_list.SID='"+MenuPanel.SID+"')");
        				java.sql.ResultSet resultSet2 = mysqlStatement2.executeQuery("SELECT co.start_time, co.end_time, co.days, co.CID From course_catalog AS ca JOIN next_semester_course_list AS co ON ca.CID = co.CID WHERE ca.CID ='"+cid+"'");//start_time='"+start_time+"'");//course_catalog.CID IN (SELECT CID FROM current_course_total_list WHERE SID='"+MenuPanel.SID+"')");// AND current_course_total_list.SID='"+MenuPanel.SID+"')");
        				
        				//while (resultSet.next()&&resultSet2.next()) {
        					while(resultSet2.next()){
        					//String course_number= resultSet.getString(1);
        					//String course_section=resultSet.getString(3);
        					//course=course_number+"-"+course_name+"-"+course_section;
        					
        					String startTime=resultSet2.getString(1);
        					String endTime=resultSet2.getString(2);
        					String day=resultSet2.getString(3);
        					start_time=startTime;
        					end_time=endTime;
        					
        					//start_time+=startTime;
        					//end_time+=endTime;
        					days+=day;
        					
        					System.out.println(cid+": "+startTime+ " "+endTime+" "+days+" ");
        					
        					
        				}
        				con2.close();
        				}
        				catch(Exception ex){}
        			String dd=days+" "+start_time+":00 - "+end_time+":00";
        			
        			Object[] program={j,term,course_name,course_number,instructor,dd,credit_hours};
        			dtm.addRow(program);
        			System.out.println("added");
        		}
        		con.close();
        		}
        		catch(Exception ex){}
        	
        	
        	//registered courses
        	dtm2=new DefaultTableModel(data,cols2){
        		public Class getColumnClass(int c) {
                    switch (c) {
                      case 0: return Boolean.class;
                      default: return String.class;
                    }   
                }
        		 @Override
               public boolean isCellEditable(int row, int col) {
                    switch (col) {
                        case 0:
                            return true;
                        default:
                            return false;
                     }
               }
               
        	};
        	table2=new JTable(dtm2);
        	//int row2=0;
        	
        	try{
        		String dName = "com.mysql.jdbc.Driver";
        		String url = "jdbc:mysql://db4free.net:3306/studentreg14?user=studentreg14&password=KCTSkcts";
        		Connection con = DriverManager.getConnection(url);
        		java.sql.Statement mysqlStatement = con.createStatement();
        		java.sql.ResultSet resultSet = mysqlStatement.executeQuery("SELECT cu.term, cu.start_time, cu.end_time, cu.days, cu.instructor, ca.course_name, ca.course_number, ca.credit_hours, cu.CID FROM next_semester_chosen_course_list AS cu JOIN course_catalog AS ca ON cu.CID = ca.CID WHERE cu.CID IN (SELECT CID FROM next_semester_chosen_course_list WHERE SID='"+MenuPanel.SID+"') GROUP BY course_name");
        		
        		while (resultSet.next()) {
        			row2+=1;
        			String term=resultSet.getString(1);
        			String start_time="";//=resultSet.getString(2);
        			String end_time="";//=resultSet.getString(3);
        			//String days;//=resultSet.getString(4);
        			String instructor=resultSet.getString(5);
        			String course_name=resultSet.getString(6);
        			String course_number=resultSet.getString(7);
        			
        			int credit_hours=resultSet.getInt(8);
        			String cid=resultSet.getString(9);
        			String days="";
        			
        			try{
        				String dName2 = "com.mysql.jdbc.Driver";
        				String url2 = "jdbc:mysql://db4free.net:3306/studentreg14?user=studentreg14&password=KCTSkcts";
        				Connection con2 = DriverManager.getConnection(url2);
        				java.sql.Statement mysqlStatement2 = con2.createStatement();
        				//java.sql.ResultSet resultSet = mysqlStatement.executeQuery("SELECT course_name, start_time, days From course_catalog, current_course_total_list WHERE course_catalog.CID IN (SELECT CID FROM current_course_total_list WHERE SID='"+MenuPanel.SID+"')");//course_catalog.CID IN (SELECT CID FROM current_course_total_list WHERE SID='"+MenuPanel.SID+"')");// AND current_course_total_list.SID='"+MenuPanel.SID+"')");
        				java.sql.ResultSet resultSet2 = mysqlStatement2.executeQuery("SELECT co.start_time, co.end_time, co.days, co.CID From course_catalog AS ca JOIN next_semester_chosen_course_list AS co ON ca.CID = co.CID WHERE ca.CID ='"+cid+"' AND co.SID='"+MenuPanel.SID+"'");//start_time='"+start_time+"'");//course_catalog.CID IN (SELECT CID FROM current_course_total_list WHERE SID='"+MenuPanel.SID+"')");// AND current_course_total_list.SID='"+MenuPanel.SID+"')");
        				
        				//while (resultSet.next()&&resultSet2.next()) {
        					while(resultSet2.next()){
        					//String course_number= resultSet.getString(1);
        					//String course_section=resultSet.getString(3);
        					//course=course_number+"-"+course_name+"-"+course_section;
        					
        					String startTime=resultSet2.getString(1);
        					String endTime=resultSet2.getString(2);
        					String day=resultSet2.getString(3);
        					start_time=startTime;
        					end_time=endTime;
        					
        					//start_time+=startTime;
        					//end_time+=endTime;
        					days+=day;
        					
        					System.out.println(cid+": "+startTime+ " "+endTime+" "+days+" ");
        					
        					
        				}
        				con2.close();
        				}
        				catch(Exception ex){}
        			String dd=days+" "+start_time+":00 - "+end_time+":00";
        			
        			Object[] program={j,term,course_name,course_number,instructor,dd,credit_hours};
        			dtm2.addRow(program);
        			System.out.println("added");
        		}
        		con.close();
        		}
        		catch(Exception ex){}
        }
        
        
        private void add(String s){
        	
        	try{
    			String dName = "com.mysql.jdbc.Driver";
    			String url = "jdbc:mysql://db4free.net:3306/studentreg14?user=studentreg14&password=KCTSkcts";
    			Connection con = DriverManager.getConnection(url);
    			java.sql.Statement mysqlStatement = con.createStatement();
    			java.sql.ResultSet resultSet = mysqlStatement.executeQuery("SELECT COUNT(*) FROM next_semester_chosen_course_list WHERE CID IN (SELECT CID FROM course_catalog WHERE course_number='"+s+"')");
    			
    			while (resultSet.next()) {
    				int ocid=resultSet.getInt(1);
    				
    				System.out.println("cid already exist?");
    				if(ocid!=0){
    				System.out.println("course already exist");
    				}
    				else{
    					try{
    		        		String dName3 = "com.mysql.jdbc.Driver";
    		        		String url3 = "jdbc:mysql://db4free.net:3306/studentreg14?user=studentreg14&password=KCTSkcts";
    		        		Connection con3 = DriverManager.getConnection(url);
    		        		java.sql.Statement mysqlStatement3 = con3.createStatement();
    		        		//java.sql.ResultSet resultSet = mysqlStatement.executeQuery("SELECT cu.term, cu.start_time, cu.end_time, cu.days, cu.instructor, cu.CID FROM next_semester_course_list AS cu JOIN course_catalog AS ca ON cu.CID = ca.CID WHERE cu.CID IN (SELECT CID FROM next_semester_course_list WHERE SID='"+MenuPanel.SID+"') GROUP BY course_name");
    		        		java.sql.ResultSet resultSet3 = mysqlStatement3.executeQuery("SELECT term, start_time, end_time, instructor, location, CID, days FROM next_semester_course_list WHERE CID IN (SELECT CID FROM course_catalog WHERE course_number='"+s+"')");
    		        		
    		        		while (resultSet3.next()) {
    		        			//row+=1;
    		        			String term=resultSet3.getString(1);
    		        			String start_time=resultSet3.getString(2);
    		        			String end_time=resultSet3.getString(3);
    		        			String instructor=resultSet3.getString(4);
    		        			String location=resultSet3.getString(5);
    		        			String cid=resultSet3.getString(6);
    		        			String days=resultSet3.getString(7);
    		        			
    		        			try{
    		        				String dName2 = "com.mysql.jdbc.Driver";
    		        				String url2 = "jdbc:mysql://db4free.net:3306/studentreg14?user=studentreg14&password=KCTSkcts";
    		        				Connection con2 = DriverManager.getConnection(url2);
    		        				java.sql.Statement mysqlStatement2 = con2.createStatement();
    		        				mysqlStatement2.executeUpdate("INSERT INTO next_semester_chosen_course_list VALUES ('"+cid+"','"+days+"','"+instructor+"','"+location+"','"+start_time+"','"+end_time+"','"+term+"','"+MenuPanel.SID+"')");
    		        				System.out.println("course inserted into registered course list");
    		        				
    		        				con2.close();
    		        				}
    		        				catch(Exception ex){}
    		        			//Object[] program={j,term,course_name,course_number,instructor,dd,credit_hours};
    		        			//dtm2.addRow(program);
    		        			System.out.println("update added "+cid+": "+start_time+" "+days);
    		        		}
    		        		con3.close();
    		        		}
    		        		catch(Exception ex){}
    					
    					
    					int arow=0;
    		        	try{
    		        		String dName4 = "com.mysql.jdbc.Driver";
    		        		String url4 = "jdbc:mysql://db4free.net:3306/studentreg14?user=studentreg14&password=KCTSkcts";
    		        		Connection con4 = DriverManager.getConnection(url);
    		        		java.sql.Statement mysqlStatement4 = con4.createStatement();
    		        		java.sql.ResultSet resultSet4 = mysqlStatement4.executeQuery("SELECT cu.term, cu.start_time, cu.end_time, cu.days, cu.instructor, ca.course_name, ca.course_number, ca.credit_hours, cu.CID FROM next_semester_course_list AS cu JOIN course_catalog AS ca ON cu.CID = ca.CID WHERE ca.course_number='"+s+"' GROUP BY ca.course_number");
    		        		
    		        		while (resultSet4.next()) {
    		        			arow+=1;
    		        			String term=resultSet4.getString(1);
    		        			String start_time="";//=resultSet.getString(2);
    		        			String end_time="";//=resultSet.getString(3);
    		        			//String days;//=resultSet.getString(4);
    		        			String instructor=resultSet4.getString(5);
    		        			String course_name=resultSet4.getString(6);
    		        			String course_number=resultSet4.getString(7);
    		        			
    		        			int credit_hours=resultSet4.getInt(8);
    		        			String cid=resultSet4.getString(9);
    		        			String days="";
    		        			
    		        			try{
    		        				String dName2 = "com.mysql.jdbc.Driver";
    		        				String url2 = "jdbc:mysql://db4free.net:3306/studentreg14?user=studentreg14&password=KCTSkcts";
    		        				Connection con2 = DriverManager.getConnection(url2);
    		        				java.sql.Statement mysqlStatement2 = con2.createStatement();
    		        				//java.sql.ResultSet resultSet = mysqlStatement.executeQuery("SELECT course_name, start_time, days From course_catalog, current_course_total_list WHERE course_catalog.CID IN (SELECT CID FROM current_course_total_list WHERE SID='"+MenuPanel.SID+"')");//course_catalog.CID IN (SELECT CID FROM current_course_total_list WHERE SID='"+MenuPanel.SID+"')");// AND current_course_total_list.SID='"+MenuPanel.SID+"')");
    		        				java.sql.ResultSet resultSet2 = mysqlStatement2.executeQuery("SELECT co.start_time, co.end_time, co.days, co.CID From course_catalog AS ca JOIN next_semester_course_list AS co ON ca.CID = co.CID WHERE ca.CID ='"+cid+"'");//start_time='"+start_time+"'");//course_catalog.CID IN (SELECT CID FROM current_course_total_list WHERE SID='"+MenuPanel.SID+"')");// AND current_course_total_list.SID='"+MenuPanel.SID+"')");
    		        				
    		        				//while (resultSet.next()&&resultSet2.next()) {
    		        					while(resultSet2.next()){
    		        					//String course_number= resultSet.getString(1);
    		        					//String course_section=resultSet.getString(3);
    		        					//course=course_number+"-"+course_name+"-"+course_section;
    		        					
    		        					String startTime=resultSet2.getString(1);
    		        					String endTime=resultSet2.getString(2);
    		        					String day=resultSet2.getString(3);
    		        					start_time=startTime;
    		        					end_time=endTime;
    		        					
    		        					//start_time+=startTime;
    		        					//end_time+=endTime;
    		        					days+=day;
    		        					
    		        					System.out.println(cid+": "+startTime+ " "+endTime+" "+days+" ");
    		        					
    		        					
    		        				}
    		        				con2.close();
    		        				}
    		        				catch(Exception ex){}
    		        			String dd=days+" "+start_time+":00 - "+end_time+":00";
    		        			
    		        			Object[] program={j,term,course_name,course_number,instructor,dd,credit_hours};
    		        			dtm2.addRow(program);
    		        			System.out.println("added");
    		        		}
    		        		con4.close();
    		        		}
    		        		catch(Exception ex){}
    				}
    				
    			}
    			con.close();
    			}
    			catch(Exception ex){}
    		
        	
        }
        
        private void delete(String s){
        	try{
    			String dName = "com.mysql.jdbc.Driver";
    			String url = "jdbc:mysql://db4free.net:3306/studentreg14?user=studentreg14&password=KCTSkcts";
    			Connection con = DriverManager.getConnection(url);
    			java.sql.Statement mysqlStatement = con.createStatement();
    			mysqlStatement.executeUpdate("DELETE FROM next_semester_chosen_course_list WHERE CID IN (SELECT CID FROM course_catalog WHERE course_number='"+s+"')");
    			System.out.println(s+" "+"dropped?");
    			con.close();
    			}
    			catch(Exception ex){}
        }
        
        @Override
        public void paintComponent(Graphics g) {
    		super.paintComponents(g);
            g.drawImage(img, 0, 0, this);
        }
    	
    	private void button(JButton b, ImageIcon i){
    		b.setBorderPainted(false);
    		b.setBorder(null);
    		//button.setFocusable(false);
    		b.setMargin(new Insets(0, 0, 0, 0));
    		b.setContentAreaFilled(false);
    		b.setIcon(i);
    		//b.setRolloverIcon(myIcon2);
    		//b.setPressedIcon(myIcon3);
    	}
}